package com.hspedu.newData.dmsxl.树;

import com.hspedu.newData.dmsxl.ds.ListNode;
import com.hspedu.newData.dmsxl.ds.TreeNode;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-15 
 * @Version: 1.0
 */

// todo 明白了一点点，还没完全搞懂
public class LC1367二叉树中的链表 {

    public boolean isSubPath(ListNode head, TreeNode root) {
        if (root == null){
            return false;
        }
        return dfs(head, root) || isSubPath(head,root.left) || isSubPath(head,root.right);
    }

    private boolean dfs(ListNode head, TreeNode root) {
        if (root == null){
            return true;
        }
        if (head == null){
            return false;
        }
        if (head.val != root.val){
            return false;
        }

        boolean left = isSubPath(head.next, root.left);
        boolean right = isSubPath(head.next, root.right);
        return left || right;
    }
}
